﻿
@{
    ViewData["Title"] = "角色权限设置";
}
<style>
    input[type=checkbox] {
    }
</style>
@using Layui.Entities
@using Layui.Framework.Menu
@model RolePermissionViewModel
@{
    ViewBag.Title = "角色权限设置";
}
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="@Url.RouteUrl("homeIndex")">首页</a>
        </li>
        <li><a href="@Url.RouteUrl("roleIndex")">角色列表</a></li>
        <li class="active">@ViewBag.Title</li>
    </ul>
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            @ViewData["Title"]
        </h1>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <form asp-route="rolePermission" method="post" id="formRolePermission" class="form-horizontal" onsubmit="return false;">
                @Html.AntiForgeryToken()
                @Html.Hidden("Id", Model.Role.Id)
                <div class="form-group">
                    <div class="col-sm-4">
                        <div class="btn-group">
                            <button data-toggle="dropdown" class="btn dropdown-toggle">
                                @Model.Role.Name
                                <span class="ace-icon fa fa-caret-down icon-on-right"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-default">
                                @foreach (var item in Model.RoleList)
                                {
                                    <li>
                                        <a href="@Url.RouteUrl("rolePermission",new { id = item.Id })">@item.Name</a>
                                    </li>
                                }
                            </ul>
                        </div>
                        <button class="btn btn-info btn-large" type="submit" style="border-width:initial;">
                            <i class="ace-icon fa fa-check bigger-110"></i>
                            提交保存
                        </button>
                    </div>
                </div>
                <table id="user_datatable" class="table table-striped table-bordered table-hover dataTable no-footer">
                    <tbody>
                        @{
                            var nodes = Model.CategoryList.Where(o => String.IsNullOrEmpty(o.FatherID)).OrderBy(o => o.Sort).ToList();
                            foreach (var item in nodes)
                            {
                                var childList = Model.CategoryList.Where(o => o.FatherID == item.ResouceID).ToList();
                                <tr>
                                    <td style="width:250px;">
                                        <div class="checkbox">
                                            <label @(Model.Permissions != null && Model.Permissions.Any(o => o.CategoryId == item.Id) ? "class=text-danger" : "")>
                                                @if (Model.Permissions != null && Model.Permissions.Any(o => o.CategoryId == item.Id))
                                                {
                                                    <input type="checkbox" name="sysResource" value="@item.Id" checked="checked" />
                                                }
                                                else
                                                {
                                                    <input type="checkbox" name="sysResource" value="@item.Id" />
                                                }
                                                @item.Name

                                            </label>
                                            @if (item.IsMenu)
                                            {
                                                <small class="text-primary">菜单</small>
                                            }
                                        </div>
                                    </td>
                                    @if (childList.Any())
                                    {
                                        <td>
                                            <table class="table table-striped table-bordered dataTable no-footer">
                                                <tbody>
                                                    @foreach (var child in childList)
                                                    {
                                                        var threeList = Model.CategoryList.Where(o => o.FatherID == child.ResouceID).OrderBy(x => x.Sort).ToList();
                                                        <tr>
                                                            <td style="width:250px;">
                                                                <div class="checkbox">
                                                                    <label @(Model.Permissions != null && Model.Permissions.Any(o => o.CategoryId == child.Id) ? "class=text-danger" : "")>
                                                                        @if (Model.Permissions != null && Model.Permissions.Any(o => o.CategoryId == child.Id))
                                                                        {
                                                                            <input type="checkbox" name="sysResource" value="@child.Id" checked="checked" />
                                                                        }
                                                                        else
                                                                        {
                                                                            <input type="checkbox" name="sysResource" value="@child.Id" />
                                                                        }
                                                                        @child.Name
                                                                    </label>
                                                                    @if (child.IsMenu)
                                                                    {
                                                                        <small class="text-primary">菜单</small>
                                                                    } 
                                                                </div>
                                                            </td>
                                                            @if (threeList.Any())
                                                            {
                                                                <td>
                                                                    <table class="table table-striped table-bordered dataTable no-footer">
                                                                        <tbody>
                                                                            @foreach (var three in threeList)
                                                                            {
                                                                                <tr>
                                                                                    <td>
                                                                                        <div class="checkbox">
                                                                                            <label @(Model.Permissions != null && Model.Permissions.Any(o => o.CategoryId == three.Id) ? "class=text-danger" : "")>
                                                                                                @if (Model.Permissions != null && Model.Permissions.Any(o => o.CategoryId == three.Id))
                                                                                                {
                                                                                                    <input type="checkbox" name="sysResource" value="@three.Id" checked="checked" />
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    <input type="checkbox" name="sysResource" value="@three.Id" />
                                                                                                }
                                                                                                @three.Name
                                                                                            </label>
                                                                                        </div>
                                                                                    </td>
                                                                                </tr>
                                                                            }
                                                                        </tbody>
                                                                    </table>
                                                                </td>
                                                            }
                                                            else
                                                            {
                                                                <td></td>
                                                            }
                                                        </tr>
                                                    }
                                                </tbody>
                                            </table>
                                        </td>
                                    }
                                    else
                                    {
                                        <td></td>
                                    }
                                </tr>
                            }
                        }
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('#formRolePermission').submit(function () {
            $(this).ajaxSubmit(function (data) {
                location.reload();
            });
        });
    });
</script>


































